import $ from '../common';
Page({
  data: {
    idx:0,
    page:1,
    tip:'上滑加载更多',
    courselist:[],
    noimg:$.noImage
  },
  onLoad(options) {
    this.setData({
      zonecode: wx.getStorageSync('addresscode') || ''
    })
    this.getuserstudent()
  },
  onShow() {
    if(this.data.isSwitch){
      this.setData({
        user:this.data.usestudent[this.data.idx],
        page:1,
        courselist:[],
        tip:'上滑加载更多'
      })
      this.getgroups()
    }
  },
  getuserstudent() { //获取_用户下认证子女
    const { zonecode} = this.data
    $.get('/user/students/certified', {
      zonecode
    }, res => {
      let user = res.students[this.data.idx]
      this.setData({
        usestudent: res.students,
        user
      })
      if(res.students.length>0)this.getgroups()
    })
  },
  getgroups(){
    $.get('/user/growing',{
      page:this.data.page,
      limit:20,
      student_uuid:this.data.user.student_uuid||''
    },res=>{
      this.data.page++
      if(res.growings.length<20){
        this.data.tip='已经到底了'
      }else{
        this.data.tip='上滑加载更多'
      }
      this.setData({
        courselist:[...this.data.courselist,...res.growings]
      })
    })
  },
  switchchildren(){//去往学员
    $.navigateTo('/address/switchchildren')
  },
  Pigimg(e){
    const{idx,img,item}=e.currentTarget.dataset
    let arr
    if(idx==1)arr=item.imgs
    if(idx==2)arr=item.growingstudent.imgs
    wx.previewImage({
      current: img, // 当前显示图片的http链接
      urls: arr, // 需要预览的图片http链接列表
      showmenu: true,
    })
  },
  onReachBottom() {

  },

})